package alp.starcode.nudtportal.framework.common.service;

import alp.starcode.common.dict.model.DictData;
import alp.starcode.common.dict.template.DictTemplate;
import alp.starcode.common.exception.CustomException;
import alp.starcode.nudtportal.framework.constant.CodeConst;
import alp.starcode.nudtportal.framework.mybatis.dao.impl.UserAccountDaoImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Slf4j
@Service
public class CommonService {
    @Autowired
    public UserAccountDaoImpl userAccountDao;
    @Autowired
    private RestTemplate restTemplate;
    @Value("${certification.server-url-prefix}")
    String serverUrlPrefix;
    @Autowired
    DictTemplate dictTemplate;

    public List<DictData> getDictDataList(String dictType) throws Exception {
        return dictTemplate.getDictDataList(dictType);
    }

    public void isOperationAuthority(String campusNumber) throws CustomException {
        if (StringUtils.isEmpty(campusNumber)) {
            throw new CustomException(CodeConst.FUNCTION_UNAVAILABLE, "未开通校园一卡通", new Exception("未开通校园一卡通"));
        }
//        if (campusNumber.contains("XFK")) {
//            throw new CustomException(CodeConst.FUNCTION_UNAVAILABLE, "消费卡不可使用此功能", new Exception("消费卡不可使用此功能"));
//        }
        if (campusNumber.contains("V")) {
            throw new CustomException(CodeConst.FUNCTION_UNAVAILABLE, "访客卡不可使用此功能", new Exception("访客卡不可使用此功能"));
        }
    }
}
